home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************************************/
- /* */
- /* Program Name: Stiletto */
- /* */
- /* File Name: flstUtilities.c */
- /* */
- /* © Apple Computer, Inc. 1991-1995 */
- /* All Rights Reserved */
- /* */
- /* Revision History: */
- /* */
- /* Date Who Modification */
- /* */
- /* 1991-06-05 Chris Halim Original version */
- /* 1995-06-26 Jaakko Railo Version 2.0 */
- /* */
- /************************************************************************************************/
-
- /****************************************** DESCRIPTION ******************************************
-
- *************************************************************************************************/
-
- /******************************************** HEADERS *******************************************/
-
- #ifndef __ALIASES__
- #include <Aliases.h>
- #endif
-
- #ifndef __FILES__
- #include <Files.h>
- #endif
-
- #ifndef __FOLDERS__
- #include <Folders.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #include "flstUtilities.h"
-
- /****************************************** DEFINITIONS *****************************************/
-
- const short kFLSTID = (-32512);
-
- #if defined(powerc) || defined (__powerc)
- #pragma options align=mac68k
- #endif
- struct FinfType {
- short theFont;
- Style theFace;
- short theSize;
- };
- #if defined(powerc) || defined(__powerc)
- #pragma options align=reset
- #endif
-
- typedef struct FinfType FinfType;
-
-
- /****************************************** PROTOTYPES ******************************************/
-
- /******************************************** GLOBALS *******************************************/
-
- /************************************************************************************************/
- /************************************************************************************************/
-
-
- #pragma segment Utilities
- void SetDialogTextState(DialogPtr theDialog, ConstStr255Param toolName)
- {
- GrafPtr savedPort;
- TextState textInfo;
- char savedState;
- TEHandle theTEHand;
- FontInfo grafPortFontInfo;
-
- GetPort(&savedPort);
- SetPort(theDialog);
-
- /**
- ** Get the first entry of 'flst' or 'finf' found in the tool or system.
- **
- **/
-
- GetToolTextState(toolName, kFLSTID, 1, &textInfo);
-
- /**
- ** Set window's default text attribute to follow 'flst' or
- ** 'finf' of the tool.
- **
- **/
-
- theTEHand = ((DialogPeek) theDialog)->textH; // Set attribute of text edit
-
- savedState = HGetState((Handle) theTEHand);
- HLock((Handle) theTEHand);
-
- TextFont(textInfo.theFont); // Set attribute of window
- TextFace(textInfo.theFace);
- TextSize(textInfo.theSize);
-
- GetFontInfo (&grafPortFontInfo);
-
- (**theTEHand).txFont = textInfo.theFont;
- (**theTEHand).txFace = textInfo.theFace;
- (**theTEHand).txSize = textInfo.theSize;
- (**theTEHand).fontAscent = grafPortFontInfo.ascent;
- (**theTEHand).lineHeight = grafPortFontInfo.ascent
- + grafPortFontInfo.descent
- + grafPortFontInfo.leading;
-
- HSetState((Handle) theTEHand, savedState);
-
- SetPort(savedPort);
- }
-
-
- void GetToolTextState(ConstStr255Param toolName, short resourceID, short index, TextState * aTextState)
- {
- /**
- ** GetToolTextState() will open a tool with the specified name and retrieve the font information
- ** in it if one is available. If the tool doesn't have the needed 'flst' resource, the routine
- ** will look for a resource of type 'finf'. If that type still doesn't exists, the routine will
- ** search for it in the system file.
- **
- **/
-
- short savedResRef;
- short procID;
- short vRefNum;
- long dirID;
- FSSpec theSpec;
- Boolean targetIsFolder, wasAliased;
-
- aTextState->theFont = 0; // resort to defaults
- aTextState->theSize = 0;
- aTextState->theFace = 0;
- aTextState->theMode = srcOr;
-
- if (FindFolder (kOnSystemDisk, kExtensionFolderType, kDontCreateFolder,
- &vRefNum, &dirID) == noErr) {
-
- FSMakeFSSpec (vRefNum, dirID, toolName, &theSpec);
-
- if (ResolveAliasFile (&theSpec, true, &targetIsFolder, &wasAliased) == noErr) {
-
- if ((procID = FSpOpenResFile (&theSpec, fsRdPerm)) != -1) {
-
- savedResRef = CurResFile();
- UseResFile(procID);
-
- if (GetIndflst (resourceID, index, aTextState) != noErr)
- if (GetIndfinf (resourceID, index, aTextState) != noErr) {
- UseResFile (0);
- (void ) GetIndflst (resourceID, index, aTextState);
- }
-
- UseResFile(savedResRef);
- CloseResFile (procID);
- }
- }
- }
- }
-
-
- short GetIndflst (short resID, short index, TextState * aTextState)
- {
- short numOfEntries, i;
- Handle theResource;
- Ptr tPtr;
- Str255 fontName;
-
- theResource = Get1Resource('flst', resID);
- if (theResource == nil) return (-1);
-
- tPtr = *theResource;
- numOfEntries = *((short*) tPtr);
- tPtr += sizeof (short);
-
- for (i = 1; i <= numOfEntries; ++i) {
- BlockMove (tPtr, fontName, tPtr[0] + 1);
- tPtr += tPtr[0] + 1;
- if ((long) tPtr & 0x0001)
- tPtr ++;
-
- if (i == index) {
- GetFNum (fontName, &aTextState->theFont);
- aTextState->theFace = *((short *) tPtr);
- tPtr += sizeof(short);
- aTextState->theSize = *((short *) tPtr);
- tPtr += sizeof(short);
- aTextState->theMode = *((short *) tPtr);
- return (noErr);
- }
-
- tPtr += 3 * sizeof (short);
- }
- return (-1);
- }
-
-
- short GetIndfinf (short resID, short index, TextState * aTextState)
- {
- short numOfEntries;
- FinfType *tfinf;
- Handle theResource;
- Ptr tPtr;
-
- theResource = Get1Resource('finf', resID);
- if (theResource == nil) return (-1);
-
- tPtr = *theResource;
- numOfEntries = *((short*) tPtr);
- if (index > numOfEntries) return (-1);
-
- tfinf = (FinfType *) (tPtr + sizeof(short) + (index-1) * sizeof (FinfType));
-
- aTextState->theFont = tfinf->theFont;
- aTextState->theFace = tfinf->theFace;
- aTextState->theSize = tfinf->theSize;
- aTextState->theMode = srcOr;
-
- return (noErr);
- }
-
-
-